<template>
	<view style="width: 750rpx;box-sizing: border-box;padding:33rpx 27.77rpx 0 27.77rpx;background: #F5F5F5;height: 100%;overflow: hidden;">
		<view style="width: 694.6rpx;border-radius: 24.15rpx;background: #FFFFFF;box-sizing: border-box;padding: 47.5rpx 36.5rpx;">
			<view class="touxiang" :style="[{justifyContent: (teacher_img == ''? 'space-between' : 'flex-start')}]" @tap.stop="addl">
				<view style="color: #383838;font-weight: bold;">
					头像
				</view>
				<view v-if="teacher_img == ''" >
					<text style="color: #D6D6D6;">上传老师头像</text>
					<image src="../../../static/newshouye/rentouxiang.png" style="width: 42rpx;height: 42rpx;vertical-align: middle;margin-left: 10rpx;"></image>
				</view>
			</view>
			<view style="height: 2rpx;width: 100%;background: #E0E0E0;margin: 20rpx 0;"></view>
			<view v-if="teacher_img != ''" style="width: 100%;height: 110rpx;" @tap="qingchu">
				<image :src="teacher_img" style="width: 110rpx;height: 110rpx;border-radius: 10rpx;"></image>
			</view>
			<view style="height: 2rpx;width: 100%;background: #E0E0E0;margin: 20rpx 0;" v-if="teacher_img != ''"></view>
			<view class="touxiang" style="justify-content: space-between;align-items: center;">
				<view style="color: #383838;font-weight: bold;">
					姓名
				</view>
				<view>
					<input placeholder="请输入老师姓名" v-model="teacher_name"  class="inp" type="text"/>
				</view>
			</view>
			<view style="height: 2rpx;width: 100%;background: #E0E0E0;margin: 20rpx 0;"></view>
			<view class="touxiang" style="justify-content: space-between;align-items: center;">
				<view style="color: #383838;font-weight: bold;">
					性别
				</view>
				<view>
					 <view class="uni-list-cell-db">
						<picker @change="bindPickerChange" :range="array" >
							<view class="uni-input" :style="[{color:(teacher_sex == '老师性别' ? '#D6D6D6' : '#383838')}]">{{teacher_sex}}</view>
						</picker>
					</view>
				</view>
			</view>
			<view style="height: 2rpx;width: 100%;background: #E0E0E0;margin: 20rpx 0;"></view>
			<view class="touxiang" style="justify-content: space-between;align-items: center;">
				<view style="color: #383838;font-weight: bold;">
					老师电话
				</view>
				<view>
					<input placeholder="请输入老师手机号码" v-model="teacher_phone" class="inp" style="width: 450rpx;" @blur="chu" type="number"/>
				</view>
			</view>
		</view>
		<view style="font-size: 32rpx;font-weight: bold;color: #343434;margin: 75.5rpx 0 29rpx 0;letter-spacing: 2rpx;margin-left: 10rpx;">
			设置老师账号
		</view>
		<view style="width: 694.6rpx;border-radius: 24.15rpx;background: #FFFFFF;box-sizing: border-box;padding: 47.5rpx 36.5rpx;">
			<view class="touxiang" style="justify-content: space-between;align-items: center;">
				<view style="color: #383838;font-weight: bold;">
					登录账号
				</view>
				<view>
					<input placeholder="输入老师登录账号" v-model="teacher_login_zhang"  class="inp" style="width: 450rpx;" type="text"/>
				</view>
			</view>
			<view style="height: 2rpx;width: 100%;background: #E0E0E0;margin: 20rpx 0;"></view>
			<view class="touxiang" style="justify-content: space-between;align-items: center;">
				<view style="color: #383838;font-weight: bold;">
					登录密码
				</view>
				<view>
					<input placeholder="输入老师登录密码" v-model="teacher_login_pass"  class="inp" style="width: 450rpx;" type="text"/>
				</view>
			</view>
		</view>
		<view style="position: fixed;width: 648.7rpx;height: 85.76rpx;line-height: 85.76rpx;background: #EE7B30;text-align: center;color: #FFFFFF;font-size: 29rpx;border-radius: 42.9rpx;bottom: 40rpx;left: 50.736rpx;" @tap="gotianjia">
			修改完成
		</view>
		<view style="width: 110rpx;height: 50rpx;background: #EE7B30;color: #FFFFFF;font-size: 23rpx;line-height: 50rpx;text-align: center;position: fixed;top: 20rpx;right: 30rpx;z-index: 1212122;border-radius: 20rpx;" @tap="gotianjian">
			删除老师
		</view>
	</view>
</template>
<script>
	import qiniu from "../../../common/qiniuUploader.js"
	export default {
		data(){
			return {
				teacher_img: "",
				key: "",
				token: "",
				teacher_name: "",
				array:["男","女"],
				teacher_sex: "老师性别",
				teacher_phone: "",
				teacher_login_zhang: "",
				teacher_login_pass: "",
				mechanism_id: "",
				list: "",
				teater_id: ""
			}
		},
		methods:{
			chu(){
				if(this.teacher_phone != ""){
					let reg = /^1(3[0-9]|4[5,7]|5[0,1,2,3,5,6,7,8,9]|6[2,5,6,7]|7[0,1,7,8]|8[0-9]|9[1,8,9])\d{8}$/;
					let panduan = reg.test(this.teacher_phone)
					if(!panduan){
						uni.showToast({
							title:"请填写正确手机号码",
							icon:"none"
						})
						this.teacher_phone = ""
					}
				}
			},
			async	gotianjian(){
					let me = this
					let sex = ""
					if(me.teacher_sex == "男"){
						sex = 1
					}else{
						sex = 2
					}
					if(sex == "" || me.teacher_phone == "" || me.teacher_login_pass == "" || me.teacher_login_zhang == "" || me.teacher_img == "" || me.teacher_name == ""){
						uni.showToast({
							title:"请完善信息",
							icon:"none"
						})
					}else{
						const res = await me.$myRequest({
							url:"/masterInfo/updateMechanismMasterInfo",
							methed: "post",
							data:{
								login_pass: me.teacher_login_pass,
								login_name: me.teacher_login_zhang,
								nick_name: me.teacher_name,
								mechanism_id: me.mechanism_id.toString(),
								avatar: me.teacher_img,
								mobile: me.teacher_phone,
								sex: sex.toString(),
								register_platform:"wx",
								id: me.teater_id,
								status: 4
							},
							header:{
								'content-type':'application/json'
							}
						})
						if(res.code == 0){
							uni.showToast({
								title:"删除成功"
							})
							uni.navigateBack({
							    delta: 1
							})
						}
					}
				},
		async	gotianjia(){
				let me = this
				let sex = ""
				if(me.teacher_sex == "男"){
					sex = 1
				}else{
					sex = 2
				}
				if(sex == "" || me.teacher_phone == "" || me.teacher_login_pass == "" || me.teacher_login_zhang == "" || me.teacher_img == "" || me.teacher_name == ""){
					uni.showToast({
						title:"请完善信息",
						icon:"none"
					})
				}else{
					const res = await me.$myRequest({
						url:"/masterInfo/updateMechanismMasterInfo",
						methed: "post",
						data:{
							login_pass: me.teacher_login_pass,
							login_name: me.teacher_login_zhang,
							nick_name: me.teacher_name,
							mechanism_id: me.mechanism_id.toString(),
							avatar: me.teacher_img,
							mobile: me.teacher_phone,
							sex: sex.toString(),
							register_platform:"wx",
							id: me.teater_id
						},
						header:{
							'content-type':'application/json'
						}
					})
					if(res.code == 0){
						uni.showToast({
							title:"修改成功"
						})
						uni.navigateBack({
						    delta: 1
						})
					}
				}
			},
			bindPickerChange: function(e) {
				let num = parseInt(e.target.value)
				this.teacher_sex = this.array[num]
			},
			qingchu(){
				this.teacher_img = ""
			},
			to(){
				this.key = Math.ceil(Math.random()*1000000)
				uni.request({
					url:"https://www.curiousmore.com/qmore/push/upload/getToken",
					data:{
						key:this.key
					},
					method:"post",
					success:(res) => {
						this.token = res.data.data
					}
				})
			},
			addl(){
				let me = this
				uni.showActionSheet({
				  itemList: ['从手机相册选择', '拍照'],
				  success: function(res) {
					let aa = []
					if(res.tapIndex == 1){
						aa = ["camera"]
					}else{
						aa = ["album"]
					}
					me.to()
					uni.chooseImage({
						count: 1,
						sizeType: ['compressed'],
						sourceType: aa,
						success:(res_) => {
							let filePath = res_.tempFilePaths[0]
							if(me.token != ""){
								qiniu.upload(filePath, (res) => {
									me.teacher_img = res.fileUrl
								}, (error) => {
									console.log('error: ' + error);
								}, {
									region: 'ECN',
									domain: 'http://img.curiousmore.com', 
									key: me.key, 
									uptoken: me.token, 
								}, (res) => {
									
								}, () => {
									// 取消上传
								}, () => {
									// `before` 上传前执行的操作
								}, (err) => {
									// `complete` 上传接受后执行的操作(无论成功还是失败都执行)
								});
							}
						}
					})
				  },
				fail: function(res) {
				    console.log(res.errMsg)
				  }
				})
			},
		},
		onLoad(option) {
			const val = JSON.parse(decodeURIComponent(option.num))
			console.log(val,"valvalvalvalval")
			this.teacher_img = val.photo
			this.teacher_name = val.full_name
			if(val.sex == 1){
				this.teacher_sex = "男"
			}else if(val.sex == 2){
				this.teacher_sex = "女"
			}
			this.teacher_phone = val.mobile
			this.teacher_login_zhang = val.login_name
			this.teacher_login_pass = val.login_pass
			this.teater_id = val.id
			this.mechanism_id = val.mechanism_id
		},
		onShow() {
			
		}
	}
</script>
<style lang="scss" scoped>
	.inp{
		text-align: right;
		width: 550rpx;
		height: 60rpx;
	}
	.touxiang{
		display: flex;
		font-size: 30rpx;
	}
	.uni-list-cell-db{
		width: 550rpx;
		height: 60rpx;
		display: flex;
		justify-content: flex-end;
		.uni-input{
			width: 550rpx;
			text-align: right;
		}
	}
</style>